import pandas as pd
from script_convert_rating import filter_unused_data
import numpy as np


def convert_ratings(input_fname, output_fname):
    rating = pd.read_csv(input_fname, names=['userID', 'itemID'], sep='\t', skiprows=1)
    # rating.rename(columns={'movieId': 'itemID'}, inplace=True)
    # rating.rename(columns={'userId': 'userID'}, inplace=True)
    rating['rating'] = 1

    rating = filter_unused_data.convert_ratings(rating)

    print(np.max(np.bincount(rating['userID'])), np.max(np.bincount(rating['itemID'])))
    n_actual_user = len(np.unique(rating['userID']))
    n_actual_item = len(np.unique(rating['itemID']))
    print(
        f"n_actual_user {n_actual_user}, n_actual_item {n_actual_item}")

    # order_l = ['userID', 'itemID', 'rating']
    # rating = rating[order_l]
    rating.to_csv(output_fname, index=False)
    print("complete {}".format(output_fname))
